<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        html, body {
            background-color: #f8f8f8;
        }
        .seller_info {
            display: -webkit-box;
            display: -webkit-flex;
            align-items: center;
            background-color: #fff;
            padding: 10px 15px;
        }
        .seller_info .seller_info_l .seller_img {
            width: 45px;
            height: 45px;
        }
        .seller_info .seller_info_l .seller_img img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .seller_info .seller_info_c {
            width: 0;
            flex: 1;
            -webkit-flex: 1;
            box-flex: 1;
            -webkit-box-flex: 1;
            padding: 0 10px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .seller_info .seller_info_r img {
            height: 13px;
            display: block;
        }
        .title_p {
            height: 35px;
            line-height: 41px;
            padding: 0 15px;
            font-size: 12px;
            color: #333;
        }
        .goods_evaluate {
            /*background-color: #fff;*/
        }
        .goods_evaluate .goods_ul .goods_li {
            border-bottom: 1px solid #e8e8e8;
            background-color: #fff;
            margin-bottom: 6px;
        }
        .goods_evaluate .goods_ul .goods_li:last-child {
            border-bottom: none;
            margin-bottom: 0px;
        }
        .goods_evaluate .goods_info {
            height: 44px;
            line-height: 44px;
            color: #333;
            font-size: 15px;
            display: -webkit-box;
            display: -webkit-flex;
        }
        .goods_evaluate .goods_info .goods_info_l {
            width: 0;
            flex: 1;
            -webkit-flex: 1;
            box-flex: 1;
            -webkit-box-flex: 1;
            padding: 0 5px 0 15px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .goods_evaluate .goods_info .goods_info_r {
            overflow: hidden;
            padding-right: 15px;
        }
        .goods_evaluate .goods_info .goods_info_r .evaluate_d {
            float: left;
            display: -webkit-box;
            -webkit-box-align: center;
            margin-right: 23px;
        }
        .goods_evaluate .goods_info .goods_info_r .evaluate_d:last-child {
            margin-right: 0;
        }
        .goods_evaluate .goods_info .goods_info_r .evaluate_d img {
            width: 12px;
            margin-left: 8px;
            display: block;
        }
        .goods_evaluate .goods_info .goods_info_r .evaluate_d span {
            font-size: 12px;
            color: #999;
            margin-left: 5px;
            display: block;
        }
        .goods_evaluate .goods_tag {
            padding-bottom: 10px;
            padding: 0 21px 10px;
            border-bottom: 1px solid #e8e8e8;
        }
        .goods_evaluate .goods_tag ul {
            overflow: hidden;
            margin: 0 -5px;
        }
        .goods_evaluate .goods_tag ul li {
            min-width: 25%;
            float: left;
            padding: 0 5px;
            margin-bottom: 10px;
            box-sizing: border-box;
        }
        .goods_evaluate .goods_tag ul li .tag_box {
            height: 24px;
            line-height: 24px;
            border: 1px solid #999;
            padding: 0 3px;
            text-align: center;
            border-radius: 5px;
            background-color: #fff;
            color: #999;
            font-size: 12px;
        }
        .goods_evaluate .goods_tag ul li .tag_box input {
            display: none;
        }
        .goods_evaluate .goods_tag ul li .tag_box.active {
            color: #e62442;
            border-color: #e62442;
        }
        .goods_evaluate .goods_text textarea {
            width: 100%;
            height: 81px;
            font-size: 14px;
            padding: 10px 15px;
            color: #999;
            display: block;
            box-sizing: border-box;
        }
        .goods_evaluate .goods_text textarea::-webkit-input-placeholder {
            color: #999;
        }
        .seller_evaluate {
            background-color: #fff;
            padding-top: 15px;
        }
        .evaluate_num_box {
            font-size: 14px;
            color: #333;
            padding: 0 15px;
            display: -webkit-box;
            -webkit-box-align: center;
            margin-bottom: 12px;
        }
        .evaluate_s {
            margin-bottom: 6px;
        }
        .evaluate_num_box .evaluate_div {
            display: -webkit-box;
            display: -webkit-flex;
            align-items: center;
            padding-left: 26px;
        }
        .evaluate_num_box .evaluate_div .evaluate_icon {
            overflow: hidden;
            margin-right: 7px;
        }
        .evaluate_num_box .evaluate_div .evaluate_icon img {
            height: 19px;
            float: left;
            padding-right: 7px;
        }
        .evaluate_num_box .evaluate_div .evaluate_icon img:last-child {
            padding-right: 0;
        }
        .evaluate_num_box .evaluate_div .evaluate_num {
            font-size: 13px;
            color: #ffa60c;
        }
        .seller_evaluate .evaluate_tag {
            padding-bottom: 10px;
            padding: 15px 21px 10px;
            border-bottom: 1px solid #e8e8e8;
        }
        .seller_evaluate .evaluate_tag ul {
            overflow: hidden;
            margin: 0 -5px;
        }
        .seller_evaluate .evaluate_tag ul li {
            min-width: 25%;
            float: left;
            padding: 0 5px;
            margin-bottom: 10px;
            box-sizing: border-box;
        }
        .seller_evaluate .evaluate_tag ul li .tag_box {
            height: 24px;
            line-height: 24px;
            border: 1px solid #999;
            padding: 0 3px;
            text-align: center;
            border-radius: 5px;
            background-color: #fff;
            color: #999;
            font-size: 12px;
        }
        .seller_evaluate .evaluate_tag ul li .tag_box input {
            display: none;
        }
        .seller_evaluate .evaluate_tag ul li .tag_box.active {
            color: #e62442;
            border-color: #e62442;
        }
        .seller_evaluate .evaluate_text {
            border-bottom: 1px solid #e8e8e8;
        }
        .seller_evaluate .evaluate_text textarea {
            width: 100%;
            height: 83px;
            font-size: 14px;
            padding: 10px 15px;
            color: #999;
            display: block;
            box-sizing: border-box;
        }
        .seller_evaluate .evaluate_text textarea::-webkit-input-placeholder {
            color: #999;
        }
        .seller_evaluate .evaluate_img {
            padding: 15px 15px 10px;
        }
        .seller_evaluate .evaluate_img ul {
            overflow: hidden;
        }
        .seller_evaluate .evaluate_img ul li {
            float: left;
            margin-right: 10px;
            margin-bottom: 10px;
        }
        .seller_evaluate .evaluate_img ul li .img_box {
            width: 50px;
            height: 50px;
        }
        .seller_evaluate .evaluate_img ul li .img_box img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .seller_evaluate .evaluate_img ul li .camera {
            width: 50px;
            height: 50px;
            background-color: #f5f5f5;
            display: -webkit-box;
            -webkit-box-align: center;
            -webkit-box-pack: center;
        }
        .seller_evaluate .evaluate_img ul li .camera img {
            width: 100%;
            height: 100%;
            display: block;
        }
        .goods_evaluate .goods_info .goods_info_r .evaluate_d span.active {
            color: #e62442;
        }
        input,textarea {
            outline: none;
        }
    </style>
</head>
<body>
    <div class="seller_info">
        <div class="seller_info_l">
            <div class="seller_img">
                <img class="shop_img" src="../image/default.png">
            </div>
        </div>
        <div class="seller_info_c shop_title">商家名称</div>
        <div class="seller_info_r">
            <img src="../image/right.png">
        </div>
    </div>
    <div class="title_p goods_comment">商品评价</div>
    <div class="goods_evaluate">
        <ul id="goods_ul" class="goods_ul">
            <!-- <li class="goods_li">
                <div class="goods_info">
                    <div class="goods_info_l">鱼丸烤肉双拼饭</div>
                    <div class="goods_info_r">
                        <div class="evaluate_d">
                            <img src="../image/evaluate_good.png" >
                            <span>好证</span>
                        </div>
                        <div class="evaluate_d">
                            <img src="../image/evaluate_bad.png" >
                            <span>差证</span>
                        </div>
                    </div>
                </div>
                <div class="goods_tag">
                    <ul>
                        <li>
                            <div class="tag_box" tapmode onclick="fnTag(this);">
                                <input type="checkbox" name="goods_val">
                                干净卫生
                            </div>        
                        </li>
                        <li>
                            <div class="tag_box" tapmode onclick="fnTag(this);">
                                <input type="checkbox" name="goods_val">
                                食材新鲜
                            </div>         
                        </li>
                        <li>
                            <div class="tag_box" tapmode onclick="fnTag(this);">
                                <input type="checkbox" name="goods_val">
                                分量足
                            </div>             
                        </li>
                        <li>
                            <div class="tag_box" tapmode onclick="fnTag(this);">
                                <input type="checkbox" name="goods_val">
                                味道好
                            </div>             
                        </li>
                        <li>
                            <div class="tag_box" tapmode onclick="fnTag(this);">
                                <input type="checkbox" name="goods_val">
                                包装精美
                            </div>          
                        </li>
                        <li>
                            <div class="tag_box" tapmode onclick="fnTag(this);">
                                <input type="checkbox" name="goods_val">
                                实惠
                            </div>               
                        </li>
                    </ul>
                </div>
                <div class="goods_text">
                    <textarea placeholder="请发表您的评价"></textarea>
                </div>
            </li> -->

        </ul>
    </div>
    <div class="title_p">商家评价</div>
    <div class="seller_evaluate">
        <div class="evaluate_num_box service_score">
            服务态度
            <div class="evaluate_div">
                <div class="evaluate_icon">
                    <img data="1" src="../image/evaluate_on.png">
                    <img data="2" src="../image/evaluate_on.png">
                    <img data="3" src="../image/evaluate_on.png">
                    <img data="4" src="../image/evaluate_on.png">
                    <img data="5" src="../image/evaluate_on.png">
                </div>
                <div class="evaluate_num service_s">5</div>
            </div>
        </div>
        <div class="evaluate_num_box goods_score evaluate_s">
            商品评价
            <div class="evaluate_div">
                <div class="evaluate_icon">
                    <img data="1" src="../image/evaluate_on.png">
                    <img data="2" src="../image/evaluate_on.png">
                    <img data="3" src="../image/evaluate_on.png">
                    <img data="4" src="../image/evaluate_on.png">
                    <img data="5" src="../image/evaluate_on.png">
                </div>
                <div class="evaluate_num goods_s">5</div>
            </div>
        </div>
        <div class="evaluate_tag">
            <ul id="shop_tag">
<!--                 <li>
                    <div class="tag_box" tapmode onclick="fnTag(this);">
                        <input type="checkbox" name="seller_val">
                        干净卫生
                    </div>        
                </li> -->
            </ul>
        </div>
        <div class="evaluate_text">
            <textarea class="shop_comment" placeholder="请发表您的评价"></textarea>
        </div>
        <div class="evaluate_img">
            <ul id="upload_box">
                <li class="upload_img" onclick="fnUploadImg();" tapmode>
                    <div class="camera">
                        <img src="../image/upload_img.png">
                    </div>
                </li>
                     
            </ul>
        </div>
    </div>

    <div class="title_p">骑手评价</div>
    <div class="seller_evaluate">
        <div class="evaluate_num_box staff_service_score">
            服务态度
            <div class="evaluate_div">
                <div class="evaluate_icon">
                    <img data="1" src="../image/evaluate_on.png">
                    <img data="2" src="../image/evaluate_on.png">
                    <img data="3" src="../image/evaluate_on.png">
                    <img data="4" src="../image/evaluate_on.png">
                    <img data="5" src="../image/evaluate_on.png">
                </div>
                <div class="evaluate_num staff_service_s">5</div>
            </div>
        </div>
        <div class="evaluate_num_box staff_delivery_score evaluate_s">
            配送速度
            <div class="evaluate_div">
                <div class="evaluate_icon">
                    <img data="1" src="../image/evaluate_on.png">
                    <img data="2" src="../image/evaluate_on.png">
                    <img data="3" src="../image/evaluate_on.png">
                    <img data="4" src="../image/evaluate_on.png">
                    <img data="5" src="../image/evaluate_on.png">
                </div>
                <div class="evaluate_num staff_delivery_s">5</div>
            </div>
        </div>
        <div class="evaluate_tag">
            <ul id="staff_tag">
<!--                 <li>
                    <div class="tag_box" tapmode onclick="fnTag(this);">
                        <input type="checkbox" name="seller_val">
                        干净卫生
                    </div>        
                </li> -->
            </ul>
        </div>
        <div class="evaluate_text">
            <textarea class="staff_comment" placeholder="请发表您的评价"></textarea>
        </div>
    </div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script id="shopTagTpl" type="text/x-dot-template">
    {{ for(var i=0;i<it.length;i++){ }}
        <li>
            <div class="tag_box" tag_id="{{=it[i]['id']}}" tapmode onclick="fnTag(this);">
                <input type="checkbox" name="seller_val">
                {{=it[i]['name']}}
            </div>        
        </li>   
    {{ }; }}
</script>
<script id="goodsTpl" type="text/x-dot-template">
    {{ for(var i=0;i<it.length;i++){ }}
        <li class="goods_li" goods_id="{{=it[i]['goods_id']}}">
            <div class="goods_info">
                <div class="goods_info_l g_name">{{=it[i]['goods_name']}}</div>
                <div class="goods_info_r">
                    <div class="evaluate_d" onclick="fnOpinion(this);" tapmode>
                        <img src="../image/evaluate_good.png" >
                        <span class="opinion" opinion="1" >好评</span>
                    </div>
                    <div class="evaluate_d" onclick="fnOpinion(this);" tapmode>
                        <img src="../image/evaluate_bad.png" >
                        <span class="opinion" opinion="2" >差评</span>
                    </div>
                </div>
            </div>
            <div class="goods_tag">
                <ul>
                    {{ for(var j=0;j<goods_tags.length;j++){ }}
                        <li>
                            <div class="tag_box" tag_id="{{=goods_tags[j]['id']}}" tapmode onclick="fnTag(this);">
                                <input type="checkbox" name="goods_val" value="{{=goods_tags[j]['id']}}">
                                {{=goods_tags[j]['name']}}
                            </div>        
                        </li>
                    {{ }; }}
                </ul>
            </div>
            <div class="goods_text">
                <textarea class="comment_content" placeholder="请发表您的评价"></textarea>
            </div>
        </li>
    {{ }; }}
</script>
<script id="staffTpl" type="text/x-dot-template">
    {{ for(var i=0;i<it.length;i++){ }}
        <li>
            <div class="tag_box" tag_id="{{=it[i]['id']}}" tapmode onclick="fnTag(this);">
                <input type="checkbox" name="seller_val">
                {{=it[i]['name']}}
            </div>        
        </li>   
    {{ }; }}
</script>
<script type="text/javascript">
    apiready = function(){
        order_id = api.pageParam.order_id;
        user = $api.getStorage('user_data');
        // 服务态度
        serviceScore('service_score');
        // 商品评价
        serviceScore('goods_score');
        // 骑手服务态度 - tim
        serviceScore('staff_service_score');
        // 骑手配送速度
        serviceScore('staff_delivery_score');
        fnGetCommentTag();

        //监听订单提交
        api.addEventListener({
            name: 'submitCommentEvent'
        }, function(ret, err) {
            if (ret) {
                //逻辑处理
                var can_submit = true;
                var submitObj = {};
                submitObj['goods'] = [];
                $('.goods_li').each(function(i,v){
                    var goods_tmp = {};
                    var goods_id = $(this).attr('goods_id');
                    goods_tmp['goods_id'] = goods_id;
                    //好评差评,没选默认好评
                    if($(this).find('.opinion.active').length > 0) {
                        goods_tmp['opinion'] = $(this).find('.opinion.active').attr('opinion');
                    }else {
                        goods_tmp['opinion'] = 1;
                    }
                    //选择标签
                    var tags = [];
                    $(this).find('.tag_box.active').each(function(){
                        var tag_id = $(this).attr('tag_id');
                        tags.push(tag_id);
                    })
                    goods_tmp['tags'] = tags;
                    //评论内容
                    var comment_content = $(this).find('.comment_content').val();
                    var goods_name = $(this).find('.g_name').text();
                    if(comment_content.length > 100){
                        msg = '评价内容不可超出100字';
                        can_submit = false;
                        return;
                    }
                    /*if(!comment_content) {
                        msg = '请先为'+goods_name+'做出评价';
                        can_submit = false;
                        return;
                    }*/
                    goods_tmp['content'] = comment_content;
                    submitObj['goods'].push(goods_tmp);

                })
                //塞入店铺评论
                submitObj['shop'] = {};
                submitObj['shop'].service_score = $('.service_s').text();
                submitObj['shop'].goods_score = $('.goods_s').text();
                var shop_tags = [];
                $('#shop_tag .tag_box.active').each(function(){
                    var tag_id = $(this).attr('tag_id');
                    shop_tags.push(tag_id);
                })
                submitObj['shop'].shop_tag = shop_tags;
                var shop_comment = $('.shop_comment').val();
                if(shop_comment.length > 100){
                    can_submit = false;
                    msg = '评价内容不可超出100字';
                }
                /*if(!shop_comment) {
                    can_submit = false;
                    msg = '请给商家一个评论内容，谢谢';
                }*/
                submitObj['shop'].shop_comment = shop_comment;
                submitObj['shop']['shop_comment_picture'] = img_arr;
                submitObj['order_id'] = order_id;
                // 组合一个sumitOjb['staff'] - tim
                submitObj['staff'] = {};
                submitObj['staff'].staff_service_score = $('.staff_service_s').text();
                submitObj['staff'].staff_delivery_score = $('.staff_delivery_s').text();
                var staff_tags = [];
                $('#staff_tag .tag_box.active').each(function(){
                    var tag_id = $(this).attr('tag_id');
                    staff_tags.push(tag_id);
                })
                submitObj['staff'].staff_tag = staff_tags;
                var staff_comment = $('.staff_comment').val();
                if(staff_comment.length > 100){
                    can_submit = false;
                    msg = '评价内容不可超出100字';
                }
                /*if(!staff_comment) {
                    can_submit = false;
                    msg = shop_comment?'请给骑手一个评论内容，谢谢':'请给商家一个评论内容，谢谢';
                }*/
                submitObj['staff'].staff_comment = staff_comment;
                //提交
                if(can_submit == false) {
                    api.toast({
                        msg: msg,
                        location : 'middle'
                    });
                }else {
                    openLoading();
                    api.ajax({
                        url: rootPath+'/api/order/submit_comment',
                        method: 'post',
                        data: {
                            values: { 
                                uid: user.id,
                                token:user.token,
                                order_id:order_id,
                                submitObj : JSON.stringify(submitObj)
                            },
       
                        }
                    }, function(ret, err) {
                        if (ret) {
                            if(ret.status == 200) {
                                api.toast({
                                    msg: '评论成功',
                                    location:'middle'
                                });
                                api.sendEvent({
                                    name: 'orderChangeEvent',
                                    extra: {
                                    }
                                });
                                setTimeout(function(){
                                    api.closeToWin({
                                        name: 'root'
                                    });
                                },1000)
                            }else {
                                api.toast({
                                    msg: ret.msg,
                                    location:"middle"
                                });
                            }
                        } else {
                            // alert(JSON.stringify(err));
                        }
                        closeLoading();
                    });
                }
            } 
        });
    };

    // 商家评价
    function fnTag(this_) {
        if ($(this_).children('input[type=checkbox]').is(':checked')) {
            $(this_).children('input[type=checkbox]').prop('checked', false);
            $(this_).removeClass('active');
        } else {
            $(this_).children('input[type=checkbox]').prop('checked', true);
            $(this_).addClass('active');
        }

    }

    function serviceScore(el) {
        var num = 0;
        $('.' + el + ' img').on('touchstart', function(event) {
            var iX = event.touches[0].clientX;
            var iY = event.touches[0].clientY;
            var oElement = document.elementFromPoint(iX, iY);
            var data = $(oElement).attr('data');
            var left = $('.' + el + ' .evaluate_icon')[0].getBoundingClientRect().left;
            if (iX <= left) {
                data = 0;
            }
            if (data != null) {
                for (var i = 0; i < data; i++) {
                    $('.' + el + ' img').eq(i).attr('src', '../image/evaluate_on.png');
                }
                for (var i = data; i <= $('.' + el + ' img').length; i++) {
                    $('.' + el + ' img').eq(i).attr('src', '../image/evaluate_off.png');
                }
                num = data;
                $('.' + el + ' .evaluate_num').text(num);
            }
        });

        $('.' + el + ' img').on('touchmove', function(event) {
            var iX = event.touches[0].clientX;
            var iY = event.touches[0].clientY;
            var oElement = document.elementFromPoint(iX, iY);
            var data = $(oElement).attr('data');
            var left = $('.' + el + ' .evaluate_icon')[0].getBoundingClientRect().left;
            if (iX <= left) {
                data = 0;
            }
            if (data != null) {
                for (var i = 0; i < data; i++) {
                    $('.' + el + ' img').eq(i).attr('src', '../image/evaluate_on.png');
                }
                for (var i = data; i <= $('.' + el + ' img').length; i++) {
                    $('.' + el + ' img').eq(i).attr('src', '../image/evaluate_off.png');
                }
                num = data;
                $('.' + el + ' .evaluate_num').text(num);
            }
        });
    }

    function fnGetCommentTag() {
        user = $api.getStorage('user_data');
        api.ajax({
            url: rootPath+'/api/order/comment_tag',
            method: 'get',
            data: {
                values: { 
                    uid: user.id,
                    token:user.token,
                    order_id : order_id
                },

            }
        }, function(ret, err) {
            if (ret) {
                if(ret.order) {
                    shop_id = ret.order.shop_id;
                    $('.shop_title').text(ret.order.shop_name);
                    var shop_img = formatVideoImg(ret.order.shop_img);
                    $('.shop_img').attr('src',shop_img);
                    goods_tags = ret.goods_tags;
                    appendDotData(ret.shop_tags,'shopTagTpl','shop_tag',true,false);
                    if(ret.order.goods.length > 0){
                        appendDotData(ret.order.goods,'goodsTpl','goods_ul',true,false);
                    }
                    // 循环骑手tag -tim
                    appendDotData(ret.staff_tags,'staffTpl','staff_tag',true,false);
                    if(!ret.order.goods || ret.order.goods.length <= 0){
                        $(".goods_comment").hide();
                    }
                }
            } else {
               
            }
        });
    }

    function fnOpinion(this_) {
        $(this_).parents('li').find('.opinion').removeClass('active');
        $(this_).find('.opinion').addClass('active');
    }
    var img_num = 0;
    img_arr = [];
    function fnUploadImg() {
        if(img_num >= 5) {
            api.toast({
                msg: '最多可以上传五张',
                location : 'middle'
            });
            return;
        }
        var UIMultiSelector = api.require('UIMultiSelector');
        UIMultiSelector.open({
             rect: {
                 h: 210
             },
             text: {
                 title: '上传图片',
                 leftBtn: '',
                 rightBtn: '取消',
             },
             max: 0,
             singleSelection: true,
             styles : {
                mask: 'rgba(0,0,0,0.3)',
                title: {
                    bg: '#eef2f3',
                    color:'#000',
                    size: 16,
                    h: 50
                },
                leftButton: {
                    bg: 'rgba(0,0,0,0)',
                    w: 80,
                    h: 0,
                    marginT: 5,
                    marginR: 8,
                    color: '#fff',
                    size: 14
                },
                rightButton: {
                    bg: 'rgba(0,0,0,0)',
                    w: 80,
                    h: 35,
                    marginT: 5,
                    marginR: 8,
                    color: '#1dbcd1',
                    size: 14
                },
                item : {
                    h : 80,
                    textAlign : 'center',
                    size:16
                },
                icon : {
                    w:0,
                    h:0
                }
             },
             animation: true,
             items: [{
                text : "从手机相册选择",
                status : "normal"
             },{
                text : "拍照",
                status : "normal"
             }]
        }, function(ret, err) {
             if (ret) {
                 if(ret.eventType == 'clickRight') {
                    UIMultiSelector.close();
                 }
                 if(ret.eventType == 'clickItem') {
                    var select_text = ret['items'][0]['text'];
                   if(select_text == '拍照') {
                        fnChoosePic(0);
                   }else {
                        fnChoosePic(1);
                   }
                    UIMultiSelector.close();
                 }
             } else {
                 showError(err.code,err.msg);
             }
        });
    }

    function fnChoosePic (type_) {
        if(type_)
        {
            // sourceType = 'album';
            sourceType = 'library';
        }
        else
        {
            sourceType = 'camera'; 
        }
        api.getPicture({
            sourceType: sourceType,
            encodingType: 'jpg',
            mediaValue: 'pic',
            destinationType: 'url',
            allowEdit: true,
            quality: 80,
            targetWidth: 100,
            // targetHeight: 100,
            saveToPhotoAlbum: false
        }, function( ret, err ){ 
            if(ret){
                ajaxUploadPic(ret.data);
            }else{
                // showError(err.code,err.msg);
            }
        });
    };
    function ajaxUploadPic (data_) {
        api.ajax({
            url: rootPath+'/api/user/update_photo',
            method: 'post',
            data: {
                values: { 
                    uid: user.id,
                    token: user.token,
                },
                files: { 
                    photo: data_
                }
            }
        },function(ret, err){
            if(ret.status == 200)
            {
                var head_img = formatHeadImg(ret.path);
                var html="<li  tapmode>\
                    <div class='camera'>\
                        <img src='"+head_img+"'>\
                    </div>\
                </li>";
                $('#upload_box').append(html);
                img_num++;
                img_arr.push(ret.path);
            }else{
               
            }
        });
    };
</script>
</html>